package com.quick.develop.form.controller;

import com.quick.develop.business.vo.BusinessProcessVO;
import com.quick.develop.framework.common.utils.Result;
import com.quick.develop.form.vo.FormConfigVO;
import com.quick.develop.form.vo.FormInstanceEntity;
import com.quick.develop.form.vo.FormQueryVO;
import com.quick.develop.form.application.FormApplication;
import com.quick.develop.form.service.GenDynamicFormService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RequestMapping(value = "maku-generator/form/service")
@RestController
public class FormServiceController {

    @Resource
    private FormApplication formApplication;

    @Resource
    private GenDynamicFormService genDynamicFormService;

    @GetMapping(value = "get-form")
    public Result<Object> getForm(FormQueryVO queryVO) {
        return Result.ok(formApplication.getForm(queryVO));
    }

    @GetMapping(value = "get-form-config/{key}")
    public Result<FormConfigVO> getFormConfig(@PathVariable("key") String key) {
        return Result.ok(genDynamicFormService.getFormConfigByFormKey(key));
    }

    @PostMapping(value = "handle/form")
    public Result<?> handleFormService(@RequestBody BusinessProcessVO formInstance) {
        return Result.ok(formApplication.executeFormBusiness(formInstance));
    }

    @PostMapping(value = "delete")
    public Result<?> deleteForm(@RequestBody FormQueryVO formInstance) {
        formApplication.removeForm(formInstance);
        return Result.ok();
    }
}
